package com.geekgo.lucenepp.core.config.index;

import com.geekgo.lucenepp.core.config.datasource.LuceneDataSource;
import com.geekgo.lucenepp.model.Page;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;

import java.util.ArrayList;
import java.util.List;

/**
 * 索引工厂
 *
 * @author HeHaoyang
 * @create 2017-06-13 18:16
 **/
public interface IndexFactory {

    /**添加单个索引*/
    default boolean saveIndex(LuceneDataSource dataSource, Document document){return false;}

    /**添加索引集合*/
    default boolean saveIndexs(LuceneDataSource dataSource, List<Document> documents){return false;}

    default boolean updateIndex(LuceneDataSource dataSource, Term term,Document document){return false;}

    default boolean updateIndexs(LuceneDataSource dataSource, Term term,List<Document> documents){return false;}

    /**关键字模糊查询*/
    default <T> List<T> findList(LuceneDataSource dataSource, String keyword, Class<T> clazz){
        return new ArrayList<>();
    }
    /**关键字模糊查询[分页]*/
    default <T> Page<T> findPageList(LuceneDataSource dataSource, String keyword, int pageNumber, int pageSize, Class<T> clazz){return new Page<>();}

    /**条件查找*/
    default <T> List<T> findRangeList(LuceneDataSource dataSource, Query query, Class<T> clazz){
        return new ArrayList<>();
    }
    /**条件查找*/
    default <T> List<T> findRangeListSort(LuceneDataSource dataSource, Query query, Class<T> clazz){
        return new ArrayList<>();
    }
    /**条件查找[分页]*/
    default <T> Page<T> findRangePageList(LuceneDataSource dataSource, Query query, int pageNumber, int pageSize, Class<T> obj){
        return new Page<>();
    }
    /**删除所有索引*/
    default boolean delAll(LuceneDataSource dataSource){return false;}

    /**删除通过查询*/
    default boolean deleteQuery(LuceneDataSource dataSource,Query... query){return false;}
}
